package top.ashman.demo.springcloud.hystrix;

import com.netflix.hystrix.strategy.concurrency.HystrixRequestContext;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * @author sunzhaojie
 * @date 2018-12-12
 */
@WebFilter(urlPatterns = "/my/*", filterName = "hystrixFilter", asyncSupported = true)
public class MyFilter implements Filter {
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println("Context Initialize");
        HystrixRequestContext context = HystrixRequestContext.initializeContext();
        try {
            chain.doFilter(request, response);
        } finally {
            context.shutdown();
            System.out.println("Context Shutdown");
        }
    }
}
